<?php
function blog_render_category_home($data){
	if(!$data){ return '';}
	$j=1;
	$str='';
	foreach($data as $r1){
									if($j++%2==0){
									$str.='<div class="blog-category-item row item-odd">';
									}else{
									$str.='<div class="blog-category-item row item-even">';
									}
											$str.='<div class="col-md-6 col-xs-6 col-sm-6 col-xxs-12">';
												$str.='<a class="blog-list-img" href="#"><img src="'.HOME.'images/category/'.$r1['hinhanh'].'" /></a>';
												$str.='<a class="blog-category-title" href="'.$r1['url'].'">'.$r1['name'].'</a>';
												//Sub category
												if($r1['sub']){
												$str.='<div class="wrap-sub-blog-category">';
												$string="";
													foreach($r1['sub'] as $r2){
													$string.='<a href="'.$r2['url'].'" class="sub-blog-category badge">'.$r2['name'].'</a> - '; 
													}
													$string=substr($string,0,strlen($string)-3);
													$str.=$string;
													
												$str.='</div>';
												} // IF(SUB)
												$str.='<div class="clr"></div>';
												$str.='<p class="blog-category-des">'.$r1['gioithieu'].'</p>';
											$str.='</div>';
											
											$str.='<div class="col-md-6 col-xs-6 col-sm-6 col-xxs-12">';
												if($r1['post']){
													foreach($r1['post'] as $r3){
												$str.='<p class="newest-blog-p"><a class="newest-blog" href="'.$r3['url'].'">'.$r3['name'].'</a></p>';
													}
												
												}// End if($r1['post'])
												
											$str.='</div>';
											
											
										$str.='</div>';
	} // End foreach category
	return $str;
}

function blog_render_row_home_tab($data){
	if($data){
			$num=count($data);
			$rows=ceil($num/2);
				for($i=0;$i<$rows;$i++){
						$j=$i*2;
						$dt=array_slice($data,$j,2);
						$str.='<div class="panel-featured-row">';
						foreach($dt as $row){
										$str.='<div class="col-md-12 col-sm-12 col-lg-6 col-xs-12 col-xxs-12 col-xxxs-12">';
												$str.='<div class="blog-list-item">';
														$str.='<span class="wrap-blog-item-img" ><img src="'.$row['user']['avatar'].'"  /></span>';
														$str.='<h4>';
															$str.='<a href="'.$row['url'].'">'.$row['name'].'</a>';
															$str.='<span class="paragraph-end"></span>';
														$str.='</h4>';
														
														$str.='<span class="blog-featured-item-user"><i class="fa fa-user"></i> <a href="'.blog_url_user($row['upload_user']).'">'.$row['user']['name'].'</a>';
														
													$str.='</span>';
														$str.='<span class="blog-featured-item-time"><i class="fa fa-clock-o"></i> '.time_ago($row['upload_time']).'</span>';
														$str.='<div class="clr"></div>';
													$str.='</div>';
												$str.='</div>';
						}
						$str.='<div class="clr"></div>';
						$str.='</div>';
				}
		
	}//End if($data)

	return $str;
}


function blog_render_row_category($data){
	if($data){
			$num=count($data);
			$rows=ceil($num/2);
			$ii = 2;
				for($i=0;$i<$rows;$i++){
						$j=$i*2;
						$dt=array_slice($data,$j,2);
						//$str.='<div class="panel-featured-row">';
						
						foreach($dt as $row){
							if($ii % 2 == 0) 
							{
								$class_item = 'item-odd';
							}else{
								$class_item='item-even';
							};
							$ii++;
							
										$str.='<div class="col-md-12" style="padding: 0px;">';
												$str.='<div class="blog-list-item  '.$class_item.'">';
														$str.='<span class="wrap-blog-item-img" ><img class="category-detail-avatar" src="'.$row['user']['avatar'].'"  /></span>';
														$str.='<h4>';
															$str.='<a href="'.$row['url'].'">'.$row['name'].'</a>';
															//$str.='<span class="paragraph-end"></span>';
														$str.='</h4>';
														
														$str.='<span class="blog-featured-item-user"><i class="fa fa-user"></i> <a href="'.blog_url_user($row['upload_user']).'">'.$row['user']['name'].'</a>';
														
													$str.='</span>';
														$str.='<span class="blog-featured-item-time"><i class="fa fa-clock-o"></i> '.time_ago($row['upload_time']).'</span><Br/>';
														
														$str.='<span class="blog-featured-item-user"><i class="fa fa-comments"></i> 150 </span>';
														$str.='<span class="blog-featured-item-time"><i class="fa fa-eye"></i> 150 </span>';
														
														$str.='<div class="clr"></div>';
													$str.='</div>';
												$str.='</div>';
												
						}
						
						//$str.='<div class="clr"></div>';
						//$str.='</div>';
				}
		
		
	}//End if($data)

return $str;
}

function blog_render_item_right($data){
					foreach($data as $row){
								 if($j++%2==0){
                                   echo ' <div class="item-odd each-comment-item row" style="margin:0px">';
								   }else{
									    echo '  <div class="item-even each-comment-item row" style="margin:0px">';
								   }?>
                                  	  		<div class="col-md-2 col-lg-2 col-sm-2 col-xs-2 col-xxs-2" style="padding:0px" ><img src="<?php echo $row['user']['avatar'] ?>" class="img-responsive" /></div>
                                                <div class="col-md-10 col-lg-10 col-sm-10 col-xs-10 col-xxs-10" style="padding:0px; padding-left:5px">	
                                                    <a title="Now" href="<?php echo $row['url'];?>" class="each-comment-title"><?php echo $row['name'] ?></a>
                                                    <span class="comment-time">2 ngày trước</span>
                                                 
                                                    <p class="each-comment-des"><i class="fa fa-user"></i> <a href="<?php echo blog_url_user($row['upload_user']);?>"><?php echo $row['user']['name'];?></a></p>
                                                </div>
                                        
									</div>
<?php
					}
}

function blog_render_comment($data,$upload_user){
	foreach($data as $row){
?>
	<div class="blog-detail-sub-title">
									<h2 class="pull-left"><?php echo $row['name']; ?></h2>
									<p class="date-created pull-right"><?php echo $row['upload_time']; ?></p>
									<div class="clr"></div>
								</div>
								<div class="panel-title blog-detail-user-title">
									
										<a class="blog-title-avatar" href="#"><img src="<?php echo $row['user']['avatar']; ?>" alt="" /></a>
										<div class="blog-title-user-info">
											<p class="blog-title-username"><a href="<?php echo blog_url_user($row['upload_user']); ?>"><?php echo show_username($row['upload_user'],$row['user']['name']); ?></a></p>
											<p><i class="fa fa-clock-o"></i> Ngày tham gia: <?php echo $row['user']['date_registered']; ?></p>
										</div>
										
									
									<div class="clr"></div>
								</div>
								
								<div class="blog-each-section">
									<div class="comment-content-view">
										<?php echo $row['content']; ?>
									</div>
                                        <!-- Manage Post -->
                         <div class="manage-blog">
                         	
                            <?php if($row['upload_time']!='' && $row['update_user']!=''){
								//Query get username 
								$re=get_user_by_username($row['update_user']);
								if($re){?>
									 <p class="pull-left blog_update_infor">
                        			Cập Nhật lần cuối bởi <b><?php echo show_username($re['username'],$re['name']) ?></b> vào <em><?php echo time_ago($row['update_time']);?></em>
                       				 </p>
							 <?php
								} //End if ($re)
							  }?>
						<!-- Single button -->
                          <?php if(isset($_SESSION['user']))
						  		if($_SESSION['user']['username']==$row['uploader_user'] || $_SESSION['user']['level']==1|| $_SESSION['user']['level']==6){ ?>
                                        <div class="btn-group pull-right">
                                            <button type="button" class="btn btn-primary dropdown-toggle"
                                                data-toggle="dropdown" aria-expanded="false">
                                                <i class="fa fa-cog"></i> Quản lý bài viết <span class="caret"></span>
                                            </button>
                                          
                                            <ul class="dropdown-menu" role="menu">
                                                <li><a href="<?php echo HOME;?>index.php?module=manage&act=blog&opt=post&pid=<?php echo $_GET['id'] ?>" target="_blank"><i class="fa fa-pencil-square-o"></i> Chỉnh Sửa Bài Viết</a></li>
                                              <?php 
											  //Chi show xoa va an neu user la admin hoac moderator --------
											 
											   if($_SESSION['user']['level']==1|| $_SESSION['user']['level']==6){?>
                                               			<?php if($row['hide']==0){?>
                                               				 <li><a href="" onclick="blog_hide(<?php echo $row['id']; ?>)"><i class="fa fa-trash"></i> Ẩn Bài Viết</a></li>
                                                     <?php }else{?>
                                                     		 <li><a href="" onclick="blog_unhide(<?php echo $row['id']; ?>)"><i class="fa fa-trash"></i> Show Bài Viết</a></li>
                                                     		<?php }?>
                                             	 <li><a onclick="blog_delete(<?php echo $row['id']; ?>)" ><i class="fa  fa-times-circle"></i> Xóa Bài Viết</a></li>
                                              <?php }else
											  if($_SESSION['user']['username']==$upload_user||$_SESSION['user']['username']==$row['upload_user']){?>
                                                			<?php if($row['hide']==0){?>
                                               				 <li><a  onclick="blog_hide(<?php echo $row['id']; ?>)"><i class="fa fa-trash"></i> Ẩn Bài Viết</a></li>
                                                     <?php }else{?>
                                                     		 <li><a  onclick="blog_unhide(<?php echo $row['id']; ?>)"><i class="fa fa-trash"></i> Show Bài Viết</a></li>
                                                     		<?php }?>
											 <?php }?>
                                            </ul>
                                        </div>
                        <?php }?>
						<div class="clr"></div>
					</div>
                                        <!-- End managepost -->
                     
								</div><!-- /.panel-featured-row -->
<?php	
	} //End foreach
}

function blog_render_mobile_menu(){
		$val=blog_get_all_category();
		$str='';
		foreach($val as $row){
			$str.='<div style="text-align:left"><a href="'.$row['url'].'"  class="panel-odd" style="font-size:20px; font-weight:lighter">'.$row['name'].'</a></div>';
			if($row['sub']){
				foreach($row['sub'] as $row2){
						$str.='<a href="'.$row2['url'].'" class="badge">'.$row2['name'].'</a>';
				}
			}
		}
		return $str;
}

?>